package likou.offer2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/09/19 15:19
 */
public class _085 {
    List<String> res = new ArrayList<>();

    public List<String> generateParenthesis(int n) {
        Parenthesis(n, n, new StringBuilder());
        return res;
    }

    private void Parenthesis(int left, int right, StringBuilder sb) {
        if (left == 0 && right == 0) {
            res.add(sb.toString());
            return;
        }
        if (left == right || left > 0) {
            Parenthesis(left - 1, right, new StringBuilder(sb).append("("));
        }
        if (right > left) {
            Parenthesis(left, right - 1, new StringBuilder(sb).append(")"));
        }
    }



    
}
